<?php

namespace App\Model;

use Illuminate\Database\Eloquent\Model;

/**
 * @property string $name
 * @property numeric $tax
 */
class OACompany extends Model
{
    protected $table = 'company';

    public static function getAllCompany($deptid=0)
    {
        $query = self::query();
        if($deptid) $query->whereRaw("FIND_IN_SET ($deptid,deptid)");

        return $query
            ->where('status',1)
            ->select([
                'id',
                'name',
                'tax',
            ])
            ->get()
            ->toArray();
    }


    public static function getUidsByCompany(int $companyId)
    {
        $position_list = config('oa.position');
        $field = [];
        foreach ($position_list as $role => $roleName){
            $field[] = "{$roleName} AS $role";
        }
        return self::query()->where('id',$companyId)->select($field)->first()->getAttributes();
    }
}
